﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using IDAL.RF.Repair;
using Model.RF.Repair;

namespace DAL.RF.Repair
{
    public class RepairLock : BaseRepository_DT<RepairLockInfo>, IRepairLock 
    {
        #region 静态变量定义部分
        private const string PARM_ID = "@ID";
        private const string PARM_PRODUCTSN = "@ProductSN";
        private const string PARM_RECORDTIME = "@RecordTime";
        private const string PARM_STEPITEM = "@StepItem";
        private const string PARM_ISVALID = "@IsValid";
        #endregion
        
        #region 检索部分
        public IList<RepairLockInfo> LoadEntities()
        {
            return null;
        }

        public RepairLockInfo LoadEntity<T1>(T1 id)
        {
            return null;
        }

        public IList<RepairLockInfo> RepairLock_GetbyProductSN(string productSN)
        {
            SqlParameter Parm = GetSNParameter();
            Parm.Value = productSN;
            return ExcuteSqlToGetEntities("RepairLock_selectbyProductSN", Parm);
        }

        public IList<RepairLockInfo> RepairLock_GetbyDT(DateTime dt1, DateTime dt2)
        {
            SqlParameter[] Parms = GetDTParameters();
            Parms[0].Value = dt1; 
            Parms[1].Value = dt2;
            return ExcuteSqlToGetEntities("RepairLock_selectlatestbyDT", Parms);
        }
        #endregion

        #region 参数部分
        public SqlParameter GetSNParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_PRODUCTSN, SqlDbType.NVarChar, 50);
            return Parm;
        }
        #endregion

        #region 重写基类部分
        public override RepairLockInfo GetEntityRecord(SqlDataReader rdr)
        {
            RepairLockInfo pro = new RepairLockInfo()
            {
                ID = rdr.GetInt32(0),
                ProductSN = rdr.GetValue(1).ToString(),
                RecordTime = rdr.GetDateTime(2),
                StepItem = rdr.GetValue(3).ToString(),
                IsValid = rdr.GetBoolean(4)
            };
            return pro;
        }

        public override RepairLockInfo GetEntityRecord()
        {
            RepairLockInfo pro = new RepairLockInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "RepairLock_Insert";
        }

        public override string GetUpdatesp()
        {
            return "RepairLock_Update";
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_ID, SqlDbType.Int, 4);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_ID, SqlDbType.Int, 4),
                    new SqlParameter(PARM_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_RECORDTIME, SqlDbType.DateTime , 8),
                    new SqlParameter(PARM_STEPITEM, SqlDbType.NVarChar, 20),
					new SqlParameter(PARM_ISVALID, SqlDbType.Bit, 1),
                };
            return parms;
        }

        public override void SetParameters(RepairLockInfo Entity, params SqlParameter[] Parms)
        {
            Parms[0].Value = Entity.ID;
            Parms[1].Value = Entity.ProductSN ;
            Parms[2].Value = Entity.RecordTime ;
            Parms[3].Value = Entity.StepItem;
            Parms[4].Value = Entity.IsValid;
        }
        #endregion
    }
}
